package org.example.friend.controller.user;

import org.example.api.domain.vo.UserQuestionResultVO;
import org.example.common.core.controller.BaseController;
import org.example.common.core.domain.Result;

import org.example.friend.domain.user.dto.UserSubmitDTO;
import org.example.friend.service.user.UserQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/user/question")
@RestController
public class UserQuestionController extends BaseController {
    @Autowired
    private UserQuestionService userQuestionService;

    /**
     * 用户提交代码的判题处理
     * @param submitDTO
     * @return
     */
    @PostMapping("/submit")
    public Result<UserQuestionResultVO> submit(@RequestBody UserSubmitDTO submitDTO) {
        return userQuestionService.submit(submitDTO);
    }

    /**
     * 使用RabbitMQ来进行判题
     * @param submitDTO
     * @return
     */
    @PostMapping("/rabbit/submit")
    public Result<Void> rabbitSubmit(@RequestBody UserSubmitDTO submitDTO) {
        return toResult(userQuestionService.rabbitSubmit(submitDTO));
    }

    /**
     * 当使用rabbitMQ来进行判题就需要通过这个接口来获取判题结果
     * @param examId
     * @param questionId
     * @param currentTime
     * @return
     */
    @GetMapping("/exe/result")
    public  Result<UserQuestionResultVO> exeResult(Long examId, Long questionId, String currentTime) {
        return Result.success(userQuestionService.exeResult(examId, questionId, currentTime));
    }
}

